package api

import (
	"github.com/gin-gonic/gin"
	"go-learn/dao"
	demo2 "go-learn/model/request"
	"go-learn/model/response"
)

func Set(c *gin.Context) {
	var data demo2.RedisString
	_ = c.ShouldBind(&data)
	err := dao.Set(data.Key, data.Value, data.Expire)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func Get(c *gin.Context) {
	var data demo2.RedisString
	_ = c.ShouldBind(&data)
	value, err := dao.Get(data.Key)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(value, c)
}
func MSet(c *gin.Context) {
	var data demo2.RedisString
	_ = c.ShouldBind(&data)
	err := dao.MSet(data.Pairs...)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
func MGet(c *gin.Context) {
	var data demo2.RedisString
	_ = c.ShouldBind(&data)
	value, err := dao.MGet(data.Keys...)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(value, c)
}
func Del(c *gin.Context) {
	var data demo2.RedisDel
	_ = c.ShouldBind(&data)
	err := dao.Del(data.Fields...)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.Ok(c)
}
